package cn.com.duiba.millionaire.center.biz.dao.impl;

import cn.com.duiba.millionaire.center.api.requestParam.AccountRecordRequestParam;
import cn.com.duiba.millionaire.center.biz.constants.DatabaseSchema;
import cn.com.duiba.millionaire.center.biz.dao.BaseDao;
import cn.com.duiba.millionaire.center.biz.dao.MillionaireConsumerAccountRecordDao;
import cn.com.duiba.millionaire.center.biz.entity.MillionaireConsumerAccountRecordEntity;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by sty on 1/18/18.
 */
@Repository
public class MillionaireConsumerAccountRecordDaoImpl extends BaseDao implements MillionaireConsumerAccountRecordDao {
    @Override
    public MillionaireConsumerAccountRecordEntity insert(MillionaireConsumerAccountRecordEntity millionaireConsumerAccountRecordEntity) {
        insert("insert", millionaireConsumerAccountRecordEntity);
        return millionaireConsumerAccountRecordEntity;
    }

    @Override
    public int batchInsert(List<MillionaireConsumerAccountRecordEntity> records) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("records", records);
        return update("batchInsert",params);
    }

    @Override
    public int queryAccountRecordPageCount(AccountRecordRequestParam param) {
        Map<String,Object> params = Maps.newHashMap();
        params.put("consumerId",param.getConsumerId());
        params.put("bizType",param.getBizType());
        return selectOne("queryAccountRecordPageCount",params);
    }

    @Override
    public List<MillionaireConsumerAccountRecordEntity> queryAccountRecordPage(
            AccountRecordRequestParam param) {
        Map<String,Object> params = Maps.newHashMap();
        params.put("startIndex", (param.getPageNum() - 1) * param.getPageSize());
        params.put("pageSize", param.getPageSize());
        params.put("consumerId",param.getConsumerId());
        params.put("bizType",param.getBizType());
        return selectList("queryAccountRecordPage",params);
    }

    @Override
    public List<MillionaireConsumerAccountRecordEntity> selectAccountListByParam(
            AccountRecordRequestParam param) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("bizId", String.valueOf(param.getActivityId()));
        params.put("minId", param.getMinId());
        params.put("bizType", param.getBizType());
        return selectList("selectAccountListByParam", params);
    }

    @Override
    public MillionaireConsumerAccountRecordEntity findByConsumerIdAndBizTypeAndBizId(Long consumerId, Integer bizType, String bizId) {
        Map<String,Object> params = Maps.newHashMap();
        params.put("consumerId",consumerId);
        params.put("bizType",bizType);
        params.put("bizId",bizId);
        return selectOne("findByConsumerIdAndBizTypeAndBizId",params);
    }

    @Override
    protected DatabaseSchema chooseSchema() {
        return DatabaseSchema.MILLIONAIRE_CONFIG;
    }
}
